﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace WebChatApi.Common
{
    /// <summary>
    /// </summary>
    public static class DateTimeUtil
    {
        /// <summary>
        /// The full date time format
        /// </summary>
        public const string FullDateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fff";

        /// <summary>
        /// Dates the time to full string.
        /// </summary>
        /// <param name="datetime">The datetime.</param>
        /// <returns></returns>
        public static string DateTimeToFullString(DateTime datetime)
        {
            return datetime.ToString(FullDateTimeFormat, CultureInfo.InvariantCulture);
        }

        /// <summary>
        /// Fulls the string to date time.
        /// </summary>
        /// <param name="fullDateTimeString">The full date time string.</param>
        /// <param name="defaultDateTime">The default date time.</param>
        /// <returns></returns>
        public static DateTime FullStringToDateTime(string fullDateTimeString, DateTime defaultDateTime = default(DateTime))
        {
            DateTime datetime;
            DateTime.TryParseExact(fullDateTimeString, FullDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out datetime);
            return datetime;
        }
    }
}
